﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Handrise.CDCable.Mobile.Business;

namespace Handrise.CDCable.Mobile.UI
{
    public partial class FrmDeviceList : FrmBase
    {
        private List<Device> devices;

        public FrmDeviceList()
        {
            InitializeComponent();
            ttlbrhead.Text = "设备台账选择";
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstdown.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstdown.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.返回01);
            ilstdown.Images.Add(ResourceImage.返回02);
            btnPrior.UpImage = ResourceImage.上一页可点击;
            btnPrior.DownImage = ResourceImage.上一页点击;
            btnPrior.DisableImage = ResourceImage.上一页灰;
            btnNext.UpImage = ResourceImage.下一页可点击;
            btnNext.DownImage = ResourceImage.下一页点击;
            btnNext.DisableImage = ResourceImage.下一页灰;
   
        }

        private void FrmDeviceList_Load(object sender, EventArgs e)
        {
            if (IsReturn)
                LoadCacheData();
            else
                LoadData();

            dlDevices.DisplayMember = "Name";
            dlDevices.DataSource = devices;
            dlDevices.DataBind();

            SetButtonState();
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            devices = (List<Device>)Parameter[0];
        }

        /// <summary>
        /// 加载缓存数据
        /// </summary>
        private void LoadCacheData()
        {
            devices = (List<Device>)Caches[0];
        }

        private void dlDevices_OnItemClick(HandRise.MBHOP.Controls.DataListItem item)
        {
            Device device = (Device)item.DataSource;
            FormManage.GotoNext("FrmDeviceDetail", new object[] { "FrmDeviceList", device }, new object[] { devices }, false);
        }

        private void bcOperate_OnButtonClick(object sender, int buttonIndex)
        {
            switch (buttonIndex)
            {
                case 2:
                    FormManage.GotoNext("FrmDeviceSelect", null, null, true);
                    break;
            }
        }

        private void SetButtonState()
        {
            btnNext.Enabled = dlDevices.PageCount > 0 && dlDevices.PageIndex < dlDevices.PageCount;
            btnPrior.Enabled = dlDevices.PageCount > 0 && dlDevices.PageIndex > 1;
            lblPageInfo.Text = dlDevices.PageIndex.ToString() + "/" + dlDevices.PageCount.ToString();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            dlDevices.NextPage();
            SetButtonState();
        }

        private void btnPrior_Click(object sender, EventArgs e)
        {
            dlDevices.PreviousPage();
            SetButtonState();
        }





    }
}